let fs = require('fs').promises
function* read() {
  let content1 = yield fs.readFile('./name.txt', 'utf-8')
  let res = yield fs.readFile(content1, 'utf-8')
  return res
}
function co(iterator) {
  return new Promise((resolve, reject) => {
    function next(data) {
      let { value, done } = iterator.next()
      if (!done) {
        Promise.resolve(value).then(data => {
          next(data)
        }, reject)//对错误处理还是不够熟练
      } else {
        resolve(data)
      }
    }

    next()

  })

}
co(read()).then(data => {
  console.log(data);
}, error => {
  console.log(error);
})
